var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken')

const { adminsLogin, salesMenLogin, validate, } = require('../service/loginService')
/* GET users listing. */
/* GET home page. */
// 管理员登录
router.post('/adminsLogin', async function (req, res, next) {
  const data = await adminsLogin(req.body);
  console.log('1111', data);
  res.send(data)
});
// 管路员登录验证
router.post('/validate', async function (req, res, next) {
  const data = await validate(req.body)

  res.send(data)
})
// 销售登录
router.post('/salesMenLogin', async function (req, res, next) {
  const data = await salesMenLogin(req.body)
  console.log(data, 1111);
  res.send(data)
});
//getUserInfo
router.post('/getUserInfo', (req, res) => {
  // 获取前端请求头中的 token
  const token = req.get('Authorization').split(' ')[1];
  const { _id, account } = jwt.verify(token, 'hello');
  res.send({
    message: '用户信息获取成功',
    code: 1,
    data: { _id, account }
  })
})

module.exports = router;